/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UnclosableDialog.java
 *
 * Created on 2011-10-09, 21:30:35
 */
package common.gui.progress;

import java.awt.Rectangle;
import javax.swing.JFrame;

/**
 *
 * @author Nobody
 */
public class UnclosableDialog extends javax.swing.JDialog implements IProgressItem {

    JFrame parent;

    public UnclosableDialog(JFrame aThis, String string) {
        super(aThis);
        initComponents();
        parent = aThis;
        setPositionInCentreOfWindow(aThis);
        setTitle(string + "...");
        Info.setText(string + "...");

    }

    public void afterReading() {
        parent.setEnabled(true);
        setVisible(false);
    }

    public void beforeReading() {
        parent.setEnabled(false);
        setVisible(true);
    }

    public int getMaximum() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void readed(double readed) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setMaximum(int maximum) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /*  public static void OpenForSavingSession(JFrame parentWindow) throws InvocationTargetException, InterruptedException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setCurrentDirectory(new File("."));
    fileChooser.setFileFilter(filter);
    if (fileChooser.showSaveDialog(parentWindow) != JFileChooser.APPROVE_OPTION) {
    return;
    }
    OpenUnclosableWindowForSaving(new UnclosableDialog(parentWindow, "Saving...", fileChooser));

    }

    public static void OpenForLoadingSession(JFrame parentWindow) throws InvocationTargetException, InterruptedException {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(filter);
    fileChooser.setCurrentDirectory(new File("."));
    if (fileChooser.showOpenDialog(parentWindow) != JFileChooser.APPROVE_OPTION) {
    return;
    }
    OpenUnclosableWindowForLoading(new UnclosableDialog(parentWindow, "Loading...", fileChooser));
    }
    /*
    public static void OpenUnclosableWindowForLoading(final UnclosableDialog unclosableDialog) throws InvocationTargetException, InterruptedException {
    java.awt.EventQueue.invokeLater(new Runnable() {

    @Override
    public void run() {
    unclosableDialog.loadSession();
    }
    });
    }

    public static void OpenUnclosableWindowForSaving(final UnclosableDialog unclosableDialog) throws InvocationTargetException, InterruptedException {
    java.awt.EventQueue.invokeLater(new Runnable() {

    @Override
    public void run() {

    unclosableDialog.saveSession();

    }
    });
    }*/
    /* public void saveSession() {
    try {
    parent.getSessionManager().saveSession(fileChooser.getSelectedFile());
    dispose();
    parent.setEnabled(true);
    } catch (Exception ex) {
    ex.printStackTrace();
    parent.showErrorPopup(ex.getMessage());
    }
    }

    public void loadSession() {
    try {
    parent.getSessionManager().loadSession(fileChooser.getSelectedFile());
    dispose();
    parent.setEnabled(true);
    } catch (Exception ex) {
    ex.printStackTrace();
    parent.showErrorPopup(ex.getMessage());
    }
    }*/
    private void setPositionInCentreOfWindow(JFrame window) {
        Rectangle mainWindowRectangle = window.getBounds();
        Rectangle thisWindowRectangle = getBounds();

        thisWindowRectangle.x = mainWindowRectangle.x + mainWindowRectangle.width / 2;
        thisWindowRectangle.y = mainWindowRectangle.y + mainWindowRectangle.height / 2;

        setBounds(thisWindowRectangle);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ContentPanel = new javax.swing.JPanel();
        Info = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setResizable(false);
        setUndecorated(true);

        ContentPanel.setOpaque(false);
        ContentPanel.setLayout(new java.awt.GridBagLayout());

        Info.setText("Loading...");
        ContentPanel.add(Info, new java.awt.GridBagConstraints());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ContentPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(ContentPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ContentPanel;
    private javax.swing.JLabel Info;
    // End of variables declaration//GEN-END:variables
}
